/**
 * 
 * @author Bui Thi Ngoc Lan <nglanbt@gmail.com>
 *
 */
$(document).ready(function(){
	// disable all questions
	$('form div ul li input').attr('disabled','disabled');
	var total_of_question = $("form div.question").size();
	var count_question = 1;			
	var current_question = $("form div.question").first();
	active_question(current_question);
	// deal with the next button to goto next question
	$('#quizzes_form .current a.active').live('click', function(){
		var current_question_id = $(this).attr('value');
		if (current_question.attr('id') == current_question_id){
			inactive_question(current_question);
			current_question = current_question.next();
			if(count_question >= total_of_question) {
				$('#quizzes_form').submit();
			} else {
			// or active next question	
				count_question++;
				active_question(current_question);
			}
			
		}
	});	
	// Active next button for each question
	// After the value be selected
	$('#quizzes_form .current ul li input').live('click', function(){
		$('#quizzes_form .current a.button').addClass('active');				
	});
	// add class current, enable input add progress
	// when active a question
	function active_question(question){
		var id = question.attr('id');
		$('#side_bar_'+id).addClass('current');
		question.addClass('current');
		$('form div.current ul li input').removeAttr("disabled");
	}
	function inactive_question(question){
		var id = question.attr('id');
		$('#side_bar_'+id).removeClass('current');
		$('#quizzes_form .current a.active').removeClass('active');
		question.removeClass('current');
	}
})	